from .base_model import BaseModel
from django.db import models
from django.contrib.auth.models import User

from .student import Student

class ClassroomEvaluation(BaseModel):
    """课堂评价模型，记录教师对课堂的整体评价"""
    
    teacher = models.ForeignKey(User, on_delete=models.CASCADE, related_name='class_evaluations', verbose_name='评价教师')
    evaluation_time = models.DateTimeField(auto_now_add=True, verbose_name='评价时间')
    DISCIPLINE_CHOICES = (
        ('excellent', '优秀'),
        ('good', '良好'),
        ('average', '一般'),
        ('poor', '较差'),
    )
    discipline_rating = models.CharField(max_length=20, choices=DISCIPLINE_CHOICES, verbose_name='纪律评级')
    overall_comment = models.TextField(blank=True, verbose_name='整体评价')

    def __str__(self):
        return f'课堂评价 - {self.evaluation_time.strftime("%Y-%m-%d %H:%M")}'

    class Meta:
        verbose_name = '课堂评价'
        verbose_name_plural = '课堂评价'


class StudentMisbehavior(BaseModel):
    """学生课堂违纪记录模型，记录具体学生的违纪行为"""
    evaluation = models.ForeignKey(ClassroomEvaluation, on_delete=models.CASCADE, related_name='misbehaviors', verbose_name='课堂评价')
    student = models.ForeignKey(Student, on_delete=models.CASCADE, related_name='class_misbehaviors', verbose_name='学生')
    MISBEHAVIOR_TYPES = (
        ('disruptive', '课堂违纪'),
        ('inattentive', '听课不认真'),
        ('sleeping', '上课睡觉'),
        ('other', '其他'),
    )
    misbehavior_type = models.CharField(max_length=20, choices=MISBEHAVIOR_TYPES, verbose_name='违纪类型')
    details = models.TextField(blank=True, verbose_name='具体情况')

    def __str__(self):
        return f'{self.student.name} - {self.get_misbehavior_type_display()}'

    class Meta:
        verbose_name = '学生违纪记录'
        verbose_name_plural = '学生违纪记录'
        unique_together = ('evaluation', 'student', 'misbehavior_type')